﻿using System;
using System.Collections.Generic;
using Loki.Utils;

namespace Luna.Data.Configuration
{
    public class ConfigurationProvider : LunaDataProvider, IConfigurationProvider
    {
        public ConnectorDataMapper ConnectorMapper { get; set; }

        protected IDatabaseManager Manager
        {
            get
            {
                return ToolKit.Engine.DataContext.Get<IDatabaseManager>();
            }
        }

        #region Store Management

        public void CreateNewStore(string storeName)
        {
            Manager.Create(storeName);
        }

        public void OpenExistingStore(string storeName)
        {
            Manager.Open(storeName);
        }

        public void MoveCurrentStoreTo(string storeName)
        {
            Manager.SaveAs(storeName);
        }

        public void CloseCurrentStore()
        {
            Manager.DisposeIfDisposable();
        }

        #endregion Store Management

        #region Connectors

        public IEnumerable<IConnectorData> GetAllConnectors()
        {
            return WrapperTransactional(T => ConnectorMapper.GetAll(T));
        }

        public IConnectorData GetConnector(Guid connectorID)
        {
            return WrapperTransactional(T => ConnectorMapper.Get(T, connectorID));
        }

        public void SaveConnector(IConnectorData connector)
        {
            WrapperTransactional(T => ConnectorMapper.Save(T, connector));
        }

        public void DeleteConnector(Guid connectorID)
        {
            WrapperTransactional(T => ConnectorMapper.Delete(T, connectorID));
        }

        #endregion Connectors
    }
}